package co.id.btel.create.pdf;

import java.io.FileOutputStream;

import utilities.CellModif;
import utilities.ChunkModif;
import utilities.Constants;
import utilities.PdfUtil;

import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Chunk;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Element;
import com.itextpdf.text.Font;
import com.itextpdf.text.FontFactory;
import com.itextpdf.text.List;
import com.itextpdf.text.ListItem;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;

public class PdfFooter {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		try {
			String FILE = "E:/BTE/samplePdf/Footer.pdf";
			Document document = new Document();
			PdfWriter writer = PdfWriter.getInstance(document,
					new FileOutputStream(FILE));
			ChunkModif event = new ChunkModif();
			writer.setPageEvent(event);
			document.open();
			PdfUtil.addMetaData(document);
			addFooter(document);
			document.close();
			System.out.print("done!");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * @param document
	 * @throws DocumentException
	 */
	public static void addFooter(Document document) throws DocumentException {

		CellModif event = new CellModif("roundRect", 0);
		PdfPTable table = new PdfPTable(3);
		table.setWidthPercentage(100);
		table.setWidths(new int[] { 19, 1, 9 });

		// sel 1
		Paragraph p = new Paragraph(" ");
		PdfPCell c1 = new PdfPCell(p);
		c1.setBorderWidth(0);
		c1.setColspan(3);
		table.addCell(c1);

		List list = new List(true, 10);
		Chunk ch = new Chunk(
				"Bea Meterai Lunas Sesuai Surat Dirjen Pajak No. SI-00001/SK/WPJ.07/KP.0803/2012 Tentang Ijin Pembubuhan Tanda Bea Meterai Lunas dengan Sistem Komputerisasi Tanggal 02 Januari 2012",
				FontFactory.getFont(FontFactory.HELVETICA, Constants.FONT_E,
						Font.NORMAL, BaseColor.BLACK));
		list.add(new ListItem(ch));

		ch = new Chunk(
				"Berdasarkan Peraturan Dirjen Pajak No. 67/PJ/2010. Informasi Pemakaian Jasa Telekomunikasi Berlaku Sebagai Faktur Pajak.",
				FontFactory.getFont(FontFactory.HELVETICA, Constants.FONT_E,
						Font.NORMAL, BaseColor.BLACK));
		list.add(new ListItem(ch));

		ch = new Chunk(
				"Tidak sampainya lembar tagihan ini tidak menghapus kewajiban pelanggan untuk membayar tagihan.",
				FontFactory.getFont(FontFactory.HELVETICA, Constants.FONT_E,
						Font.NORMAL, BaseColor.BLACK));
		list.add(new ListItem(ch));

		ch = new Chunk(
				"Layanan AHA diselenggarakan oleh PT. Bakrie Telecom Tbk dan dipasarkan kembali oleh PT. Bakrie Connectivity.\n",
				FontFactory.getFont(FontFactory.HELVETICA, Constants.FONT_E,
						Font.NORMAL, BaseColor.BLACK));
		list.add(new ListItem(ch));

		c1 = new PdfPCell();
		c1.addElement(list);
		c1.setBorderWidth(0);
		c1.setPaddingBottom(5f);
		c1.setPaddingLeft(5f);
		c1.setPaddingRight(5f);
		c1.setVerticalAlignment(Element.ALIGN_TOP);
		c1.setHorizontalAlignment(Element.ALIGN_JUSTIFIED_ALL);
		c1.setCellEvent(event);
		table.addCell(c1);

		p = new Paragraph("");
		c1 = new PdfPCell(p);
		c1.setBorderWidth(0);
		table.addCell(c1);

		p = new Paragraph();
		ch = new Chunk(
				"PT. BAKRIE TELECOM Tbk NPWP/NPPKP: 01.642.566.2.092.000 Gedung Wisma Bakrie Lantai 2, Jln. HR. Rasuna Said Kav. B-1 Jakarta Selatan 12920",
				FontFactory.getFont(FontFactory.HELVETICA, Constants.FONT_C,
						Font.NORMAL, BaseColor.BLACK));
		p.add(ch);
		c1 = new PdfPCell(p);
		c1.setBorderWidth(0);
		c1.setVerticalAlignment(Element.ALIGN_MIDDLE);
		c1.setHorizontalAlignment(Element.ALIGN_CENTER);
		// c1.setPaddingLeft(5f);
		// c1.setPaddingRight(5f);
		// c1.setPaddingTop(10f);
		// c1.setPaddingBottom(10f);
		c1.setCellEvent(event);
		table.addCell(c1);

		p = new Paragraph();
		ch = new Chunk("Terima kasih untuk kepercayaan menggunakan AHA l ",
				FontFactory.getFont(FontFactory.HELVETICA, Constants.FONT_E,
						Font.NORMAL, BaseColor.BLACK));
		p.add(ch);
		ch = new Chunk("Thank you for your trust in our AHA",
				FontFactory.getFont(FontFactory.HELVETICA, Constants.FONT_E,
						Font.ITALIC, BaseColor.BLACK));
		p.add(ch);
		c1 = new PdfPCell(p);
		c1.setBorderWidth(0);
		c1.setColspan(3);
		table.addCell(c1);

		document.add(table);
	}

}
